import http from '@/plugins/axios'

//let baseUrl = process.env.BASE_URL
let baseUrl = process.env.VUE_APP_BASE_URL

/**
 * 获取角色
 * @param {*} data 
 * @returns 
 */
export function getRoles(data) {
  return http.get(`${baseUrl}WorkflowData/roles.json`, { params: data })
}

/**
 * 获取部门
 * @param {*} data 
 * @returns 
 */
export function getDepartments(data) {
  return http.get(`${baseUrl}WorkflowData/getDepartments`, { params: data })
}

/**
 * 获取职员
 * @param {*} data 
 * @returns 
 */
export function getEmployees(data) {
  return http.get(`${baseUrl}WorkflowData/getEmployees`, { params: data })
}
/**
 * 获取条件字段
 * @param {*} data 
 * @returns 
 */
export function getConditions(data) {
  return http.get(`${baseUrl}WorkflowData/conditions.json`, { params: data })
}

function getUrlParam() {
  var url = window.location.href ;             //获取当前url
  var dz_url = url.split('#')[0];                //获取#/之前的字符串
  var cs = dz_url.split('?')[1];                //获取?之后的参数字符串
  var workFlowDefId = 0;
  console.log(cs);  
  if(cs!==undefined){

    var cs_arr = cs.split('&');                    //参数字符串分割为数组
    var cs={};
    console.log("debug afwagewgwqeg")
    for(var i=0;i<cs_arr.length;i++){         //遍历数组，拿到json对象
      cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
      console.log("debug="+cs_arr[i])
    }
    console.log(cs.workFlowDefId);                                           //这样就拿到了参数中的数据
    if (cs.workFlowDefId!==undefined){
      workFlowDefId = cs.workFlowDefId
    }
  }
  return workFlowDefId
}


/**
 * 获取审批数据
 * @param {*} data 
 * @returns 
 */
export function getWorkFlowData(data) {
  var url = window.location.href ;             //获取当前url
  var dz_url = url.split('#')[0];                //获取#/之前的字符串
  var cs = dz_url.split('?')[1];                //获取?之后的参数字符串
  var workFlowDefId = 0;
  console.log(cs);  
  if(cs!==undefined){

    var cs_arr = cs.split('&');                    //参数字符串分割为数组
    var cs={};
    console.log("debug afwagewgwqeg")
    for(var i=0;i<cs_arr.length;i++){         //遍历数组，拿到json对象
      cs[cs_arr[i].split('=')[0]] = cs_arr[i].split('=')[1]
      console.log("debug="+cs_arr[i])
    }
    console.log(cs.workFlowDefId);                                           //这样就拿到了参数中的数据
    if (cs.workFlowDefId!==undefined){
      workFlowDefId = cs.workFlowDefId
    }
  }
  //return http.get(`${baseUrl}data.json`, { params: data })
  return http.get(`${baseUrl}WorkflowDef/getWorkflowDef?ID=`+getUrlParam(), { params: data })
}
/**
 * 设置审批数据
 * @param {*} data 
 * @returns 
 */
export function setWorkFlowData(data) {
  return http.post(`${baseUrl}WorkflowDef/updateWorkflowDefByChart?ID=`+getUrlParam(), data)
}